package com.fenbi.tutor.live.module.large.large.chat.lithoview

import android.graphics.Color
import android.util.Log
import com.facebook.litho.Column
import com.facebook.litho.Component
import com.facebook.litho.ComponentContext
import com.facebook.litho.Handle
import com.facebook.litho.Row
import com.facebook.litho.annotations.FromEvent
import com.facebook.litho.annotations.FromTrigger
import com.facebook.litho.annotations.LayoutSpec
import com.facebook.litho.annotations.OnCreateLayout
import com.facebook.litho.annotations.OnEvent
import com.facebook.litho.annotations.OnTrigger
import com.facebook.litho.annotations.Prop
import com.facebook.litho.annotations.State
import com.facebook.litho.sections.Children
import com.facebook.litho.sections.SectionContext
import com.facebook.litho.sections.common.DataDiffSection
import com.facebook.litho.sections.common.RenderEvent
import com.facebook.litho.sections.common.SingleComponentSection
import com.facebook.litho.sections.widget.RecyclerCollectionComponent
import com.facebook.litho.widget.ComponentRenderInfo
import com.facebook.litho.widget.RenderInfo
import com.facebook.litho.widget.Text

/**
 * TODO 简要描述
 * @author wkm @ Zebra Inc.
 * @since 09-19-2020
 */

@LayoutSpec
object RootComponentSpec {

    @OnCreateLayout
    fun onCreateLayout(
        c: ComponentContext,
        @Prop newMsgHandle: Handle
    ): Component {
        val sc = SectionContext(c)
        return Column.create(c)
            .child(
                RecyclerCollectionComponent.create(c)
                    .flex(1.0F)
                    .disablePTR(true)
                    .handle(newMsgHandle)
                    .section(
                        ChatMsgSection.create(sc)
                            .build()
                    )
            ).child(
                Row.create(c)
                    .child(
                        Text.create(c)
                            .text("This is a tail text")
                            .heightDip(80F)
                            .backgroundColor(Color.GREEN)
                    )
            ).build()

    }

    @OnTrigger(OnNewMsgEvent::class)
    fun onNewMsg(
        c: ComponentContext,
        @Prop newMsgHandle: Handle,
        @FromTrigger msg: MsgInfo
    ) {
        Log.e("TAG", "in ${this::class.java.name} onNewMsg")
        ChatMsgSection.onNewMsg(SectionContext(c), newMsgHandle, msg)
    }


}